#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMBER_OF_STATES	4

enum states {
  STATE_SPEED0,
  STATE_SPEED250,
  STATE_SPEEDMIN250,
  STATE_NULL
};

int printState(enum states state, enum states *nextState) {
	int i;
	char next[80];
	strcpy(next, "Next possible states:\t");

	switch(state) {
		case STATE_SPEED0: 			printf("Current state: STATE_SPEED0\n"); break;
		case STATE_SPEED250: 		printf("Current state: STATE_SPEED250\n"); break;
		case STATE_SPEEDMIN250: 	printf("Current state: STATE_SPEEDMIN250\n"); break;
		case STATE_NULL: 			printf("Current state: STATE_NULL\n"); break;
		default:					printf("No current state found!\n"); break;
	}
	for (i=0;i<sizeof(nextState);i++) {
		switch(nextState[i]) {
			case STATE_SPEED0: 			strcat(next, "STATE_SPEED0\t"); break;
			case STATE_SPEED250: 		strcat(next, "STATE_SPEED250\t"); break;
			case STATE_SPEEDMIN250: 	strcat(next, "STATE_SPEEDMIN250\t"); break;
			case STATE_NULL: 			strcat(next, "STATE_NULL\t"); break;
			default:					strcat(next, "No next state found!"); break;
		}
	}
	strcat(next, "\n");
	printf("%s", next);

	return 0;
}

int main(int argc, char *argv[]) {
  enum states state;
  enum states nextState[NUMBER_OF_STATES];
  long int cmd;
  char *speed;

  if (argc < 2) {
	  printf("Please provide a state argument.\n");
	  return 0;
  }

  cmd = strtol(argv[1], &speed,10);

  if (cmd == -250) state = STATE_SPEEDMIN250;
  else if (cmd == 250) state = STATE_SPEED250;
  else if (cmd == 0) state = STATE_SPEED0;
  else state = STATE_NULL;

  switch(state) {
	  case STATE_SPEED0:
		  nextState[0] = STATE_SPEED250;
		  nextState[1] = STATE_SPEEDMIN250;
		  nextState[2] = STATE_NULL;
		  nextState[3] = STATE_NULL;
		break;
	  case STATE_SPEED250:
		  nextState[0] = STATE_SPEED0;
		  nextState[1] = STATE_NULL;
		  nextState[2] = STATE_NULL;
		  nextState[3] = STATE_NULL;
		break;
	  case STATE_SPEEDMIN250:
		  nextState[0] = STATE_SPEED0;
		  nextState[1] = STATE_NULL;
		  nextState[2] = STATE_NULL;
		  nextState[3] = STATE_NULL;
		break;
	  default:
		  state = STATE_NULL;
		  nextState[0] = STATE_SPEED0;
		  nextState[1] = STATE_NULL;
		  nextState[2] = STATE_NULL;
		  nextState[3] = STATE_NULL;
		  break;
	}
  printState(state, nextState);
}
